<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="com.milkyTea.Entity.User"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="/wk1un9/houTai/lib/layui/css/layui.css" />
</head>
<body>
	<div style="text-align: center;padding-top:50px;">
		<form class="layui-form  layui-inline" action="">
			<%
				HttpSession s = request.getSession();
				User u = (User) s.getAttribute("user");
			%>
			<div class="layui-form-item" hidden="hidden">
			<label class="layui-form-label">id:</label>
			<div class="layui-input-inline" style="width: 350px;">
				<input type="text" id="id" name="id" value="<%=u.getId()%>" class="layui-input"
					readonly="true">
			</div>
		</div>
			<div class="layui-form-item">
				<label class="layui-form-label">新密码:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="password" id="admin" name="admin" lay-verify="required"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">确认密码:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="password" lay-verify="required|confirmPass"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-btn-container">
				<button class="layui-btn" lay-filter="userEditBtu" lay-submit="">
					修改</button>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="/wk1un9/houTai/lib/layui/layui.js"></script>

	<script>
		//加载了layui的form模块
		layui.use('form', function() {
			var form = layui.form, layer = layui.layer;
			var $ = layui.jquery; //引入jquery
			// 校验两次密码是否一致
			form.verify({
				confirmPass : function(value) {
					if ($('input[name=admin]').val() !== value)
						return '两次密码输入不一致！';
				}
			});
			//监听提交
			form.on('submit(userEditBtu)', function(data) {
				var d = data.field; //表单中的数据，定义一个对象来接收
				d.method = "pwdUpdate"; // 我的密匙、大家用你们自己的
				//通过ajax向数据库提交数据了
				console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
				var url = '/wk1un9/HouUserServlet';
				//确保数据没有问题就进行ajax提交了
				$.post(url, d, function(data) {
					if (data.count > 0) {
						console.log('修改成功');
						layer.msg('修改成功');
						/* var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
						parent.layer.close(index); //关闭窗口 */
						setTimeout(() => {
							window.location.href = "/wk1un9/LoginServlet?method=loginOut";
						}, 500);
					}
				}, "json");
				return false;
			});
		});
	</script>
</body>
</html>